/**
 * Created by chenbing on 14-9-19.
 */

var mysql = require('mysql');

//my sql 连接字符串 chenbing  2014-09-19
var conn = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'chenbing',
    database:'shfl',
    port: 3306
});



//执行sql
function exeScript(sqlscript){
    conn.connect();//连接
    //执行sql
    conn.query(sqlscript, function (err, results) {
        if (err)
            console.log(err);
        else
        console.log(results);
        conn.end(); //在回调函数中处理 陈冰 2014- 09- 19
    });
}


    function select(sqlscript){
        conn.connect();//连接
        //query
        var json;
        conn.query(sqlscript, function (err, rows) {
            if (err) console.log(err);
            for (var i in rows) {
               console.log(rows[i]);
            }
            });
       conn.end();
    }

//公共模块
function del(sqlscript){
    exeScript(sqlscript);
}
function update(sqlscript){
    exeScript(sqlscript);
}
function add(sqlscript){
    exeScript(sqlscript);
}

exports.add=add;
exports.del=del;
exports.update=update;
exports.select=select;




